/**
 * @description 缓存存储
*/

import { StoreMemory, objecter } from '@daelui/dogjs/dist/components'
import { StoreUni } from './store-uni.js'

class StoreStorage extends StoreMemory {
  /**
   * @function 构造方法
  */
  constructor (args) {
    args = args || {}
    Object.assign({
      slaveConfig: {
        // 空数组或空对象
        isGetSlave (value) {
          return Array.isArray(value) && value.length === 0 || objecter.isPlainObject(value) && Object.keys(value).length === 0
        },
        isSetSlave (value) {}
      }
    })
    super(args)
		this.storer = new StoreUni(args)
  }

  /**
   * @function 设置Key
  */
	setKey (key) {
    this.key = key
    this.storer.setKey.apply(this.storer, arguments)
	}

  /**
   * @function 取数据
   * @param {any} key // 键名
   * @return {any}
  */
  getSlaveItem (key, options) {
    return this.storer.getItem.apply(this.storer, arguments)
  }

  /**
   * @function 存数据
   * @param {any} key // 键名
   * @param {any} value // 键值
   * @param {Object} options // 配置对象
  */
  setSlaveItem (key, value, options) {
    return this.storer.setItem.apply(this.storer, arguments)
  }
}

// 默认实例
const storeStorage = new StoreStorage

export default storeStorage

export {
  StoreStorage
}
